package com.ruoyi.assets.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.assets.domain.AssetsDepartment;
import com.ruoyi.assets.service.IAssetsDepartmentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 部门Controller
 * 
 * @author 孙帆科
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/AssetsDepartment")
public class AssetsDepartmentController extends BaseController
{
    @Autowired
    private IAssetsDepartmentService assetsDepartmentService;

    /**
     * 查询部门列表
     */
    @RequiresPermissions("assets:AssetsDepartment:list")
    @GetMapping("/list")
    public TableDataInfo list(AssetsDepartment assetsDepartment)
    {
        startPage();
        List<AssetsDepartment> list = assetsDepartmentService.selectAssetsDepartmentList(assetsDepartment);
        return getDataTable(list);
    }

    /**
     * 查询部门列表
     */
//    @RequiresPermissions("assets:AssetsDepartment:list")
    @GetMapping("/listDepartment")
    public AjaxResult listDepartment()
    {
//        startPage();
        List<AssetsDepartment> list = assetsDepartmentService.selectAssetsDepartmentList(null);
        return success(list);
    }

    /**
     * 导出部门列表
     */
    @RequiresPermissions("assets:AssetsDepartment:export")
    @Log(title = "部门", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetsDepartment assetsDepartment)
    {
        List<AssetsDepartment> list = assetsDepartmentService.selectAssetsDepartmentList(assetsDepartment);
        ExcelUtil<AssetsDepartment> util = new ExcelUtil<AssetsDepartment>(AssetsDepartment.class);
        util.exportExcel(response, list, "部门数据");
    }

    /**
     * 获取部门详细信息
     */
    @RequiresPermissions("assets:AssetsDepartment:query")
    @GetMapping(value = "/{departmentId}")
    public AjaxResult getInfo(@PathVariable("departmentId") Long departmentId)
    {
        return success(assetsDepartmentService.selectAssetsDepartmentByDepartmentId(departmentId));
    }

    /**
     * 新增部门
     */
    @RequiresPermissions("assets:AssetsDepartment:add")
    @Log(title = "部门", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetsDepartment assetsDepartment)
    {
        return toAjax(assetsDepartmentService.insertAssetsDepartment(assetsDepartment));
    }

    /**
     * 修改部门
     */
    @RequiresPermissions("assets:AssetsDepartment:edit")
    @Log(title = "部门", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetsDepartment assetsDepartment)
    {
        return toAjax(assetsDepartmentService.updateAssetsDepartment(assetsDepartment));
    }

    /**
     * 删除部门
     */
    @RequiresPermissions("assets:AssetsDepartment:remove")
    @Log(title = "部门", businessType = BusinessType.DELETE)
	@DeleteMapping("/{departmentIds}")
    public AjaxResult remove(@PathVariable Long[] departmentIds)
    {
        return toAjax(assetsDepartmentService.deleteAssetsDepartmentByDepartmentIds(departmentIds));
    }
}
